falsey
Returns true if value
is falsey. Works for strings, arrays and arguments
objects with a length of 0
, and objects with no own enumerable properties are considered falsey.
Install
Install with npm:
$ npm install --save falsey
What makes this lib unique (and fun) is the option to pass an array of values that should always evuate as "falsey".
This is useful for CLI prompts, web forms, etc. For example, you might want to allow users to define nil
or nope
to disable something.
Usage
var isFalsey = require('falsey');
console.log(isFalsey('nil');
Examples
All of the following return true
isFalsey(undefined);
isFalsey(null);
isFalsey(false);
isFalsey(0);
isFalsey('');
isFalsey(NaN);
isFalsey({});
isFalsey([]);
All of the following return false
:
isFalsey('foo');
isFalsey(true);
isFalsey(50);
isFalsey('10');
isFalsey({a: 'b'});
isFalsey([0]);
Special cases
There are several additional "falsey" words built in, but these can be overridden or turned off by passing a value as the second argument.
Built-in additional falsey keywords
Disable additions
isFalsey('nil', []);
Customize additions
Pass one or more keywords that should return true
when evaluated as falsey:
isFalsey('zilch', ['no', 'nope', 'nada', 'zilch']);
Extend additions
Built-in keywords are exposed on the .keywords
property. These can be used to extend the defaults:
isFalsey('zilch', isFalsey.keywords.concat(['zilch']));
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on September 11, 2017.